import {isRootPage, throttle} from "../tools/common.js";
import $ from 'jquery';

export function initNavbar() {
    const navbar = $('#navbar');
    const oldClasses = navbar.attr('class') || '';
    const newClasses = `${ navbar.attr('newClass') || ''} navbar py-8 bg-base-100 border-none`;

    const handleScroll = () => {
        const isAtTop = $(window).scrollTop() === 0;
        navbar.attr('class', isAtTop && isRootPage() ? newClasses : oldClasses);
    };

    const throttledHandleScroll = throttle(handleScroll, 100);
    $(window).on('scroll', throttledHandleScroll);
    handleScroll();
}